<?php

declare(strict_types=1);

namespace App\Info\Model;

use Mine\MineModel;

/**
 * @property int $id ID
 * @property string $title 标题
 * @property string $sub_title 副标题
 * @property string $summary 摘要
 * @property string $category_key Key
 * @property string $tag_list 标题列表
 * @property string $upload_series
 * @property string $upload_imgs 图片列表
 * @property string $upload_tags 上传列表
 * @property string $content
 * @property int $created_by
 * @property int $create_time
 * @property int $update_time
 */
class InfoProduct extends MineModel
{
    protected ?string $dateFormat = 'U';
    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'info_product';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'title', 'sub_title', 'summary', 'category_key', 'tag_list','upload_series', 'upload_imgs', 'upload_tags', 'content', 'created_by', 'create_time', 'update_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'created_by' => 'integer', 'create_time' => 'integer', 'update_time' => 'integer'];

    public function getTagListAttribute($value)
    {
        return empty($value) ? [] : json_decode($value, true);
    }

    public function setTagListAttribute($value)
    {
        $this->attributes['tag_list'] = empty($value) ? [] : json_encode($value);
    }
    public function getUploadImgsAttribute($value)
    {
        return empty($value) ? [] : json_decode($value, true);
    }

    public function setUploadImgsAttribute($value)
    {
        $this->attributes['upload_imgs'] = empty($value) ? [] : json_encode($value);
    }

    public function getUploadTagsAttribute($value)
    {
        return empty($value) ? [] : json_decode($value, true);
    }

    public function setUploadTagsAttribute($value)
    {
        $this->attributes['upload_tags'] = empty($value) ? [] : json_encode($value);
    }
}
